using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.SqlClient;

using System.Configuration;
using NUnit.Framework;

using DataAccessLayer;


namespace Entities
{
    [TestFixture]
    public class GenreFixture : ConnectionFixture
    {
        private static readonly string genreName = "Rock Genre";

        private RecordingDataSet recordingDataSet;
        private GenreGateway gateway;

        private long insertedID;

        [SetUp]
        public void SetUp()
        {
            recordingDataSet = new RecordingDataSet();
            gateway = new GenreGateway(Connection);
            insertedID = gateway.Insert(genreName, recordingDataSet);
        }

        [TearDown]
        public void TearDown()
        {
            gateway.Delete(insertedID, recordingDataSet);
        }

        [Test]
        public void Retrive()
        {
            RecordingDataSet.GenreRow row = gateway.FindById(insertedID, new RecordingDataSet());
            Assert.AreEqual(insertedID, row.id);
            Assert.AreEqual(genreName, row.name);
        }

        [Test]
        public void Delete()
        {
            RecordingDataSet emptySet = new RecordingDataSet();
            long deletedId = gateway.Insert("Deleted Name", emptySet);
            Assert.AreEqual("Deleted Name", gateway.FindById(deletedId, emptySet).name);
            gateway.Delete(deletedId, emptySet);
            Assert.IsNull(gateway.FindById(deletedId, emptySet));
        }

        [Test]
        public void Update()
        {
            RecordingDataSet.GenreRow row = gateway.FindById(insertedID, recordingDataSet);
            row.name = "Modified Genre";
            gateway.Update(recordingDataSet);
            Assert.AreEqual("Modified Genre", gateway.FindById(insertedID, new RecordingDataSet()).name);

        }

    }
}
